#!/bin/sh  /etc/rc.common
#
# Copyright (c) 2014 The Linux Foundation. All rights reserved.
#
# The shebang above has an extra space intentially to avoid having
# openwrt build scripts automatically enable this package starting
# at boot.

START=70

load_ecm() {
	[ -d /sys/module/ecm ] || insmod ecm

	sysctl -w net.bridge.bridge-nf-call-ip6tables=1
	sysctl -w net.bridge.bridge-nf-call-iptables=1
}

unload_ecm() {
	[ -d /sys/module/ecm ] && rmmod ecm

	sysctl -w net.bridge.bridge-nf-call-ip6tables=0
	sysctl -w net.bridge.bridge-nf-call-iptables=0
}

start() {
	load_ecm

	echo 'net.bridge.bridge-nf-call-ip6tables=1' >> /etc/sysctl.d/qca-nss-ecm.conf
	echo 'net.bridge.bridge-nf-call-iptables=1' >> /etc/sysctl.d/qca-nss-ecm.conf
}

stop() {
	unload_ecm

	sed '/net.bridge.bridge-nf-call-ip6tables=1/d' -i /etc/sysctl.d/qca-nss-ecm.conf
	sed '/net.bridge.bridge-nf-call-iptables=1/d' -i /etc/sysctl.d/qca-nss-ecm.conf
}
